<include file="public@storage"/>
</head>
<body>
<div class="container body-content" style="margin-top:20px;width: 100%">
    <div class="panel panel-primary" style="margin-bottom: 0.5rem">
        <div class="panel-heading"><span id="storageName">{$storageInfo[0]['name']}</span>入库单查询</div>
        <input type="hidden" id="storageUuid" value="{$storageInfo[0]['uuid']}">
        <div class="panel-body">
            <div class="row">
                <div class="col-sm-12">
                    <div id="toolbar" class="btn-group">
                        <select id="selectStorage" class="btn btn-info" style="margin-left: 5px; width: 10rem"
                                onchange="changeStorage()">
                            <option value="">请选择仓库</option>
                            <volist id="uuid" name="storageInfo" id="value">
                                <option value="{$value['uuid']}">{$value['name']}</option>
                            </volist>
                        </select>
                    </div>
                    <table id="table"></table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>

<script src="__STATIC__/storage/js/common/selectStorage.js"></script>
<script>
    var storageUuid = $("#storageUuid").val();
    $(function () {
        if ($("#storageUuid").val() === '') {
            $("#selectStorage").show();
        } else {
            $("#selectStorage").hide();
        }
        init();
    });

    function init() {
        var url = "{:url('storage/Purchase/getPurchase')}?storageUuid=" + storageUuid;
        var columns = [
            {
                title: '序号',
                width: 50,
                align: "center",
                valign: 'middle',
                formatter: function (value, row, index) {
                    return index + 1;
                }
            },
            {title: 'uuid', field: 'uuid', visible: false},
            {
                title: '单号',
                field: 'purchase_id',
                width:300,
                align: "center",
                valign: 'middle',
                filter: {
                    type: 'input'
                }
            },

            {
                title: '生成仓库',
                field: 'storage_name',
                width:300,
                align: "center",
                valign: 'middle',
                filter: {
                    type: 'input'
                }
            },
            {
                title: '时间',
                field: 'time',
                width:300,
                align: "center",
                valign: 'middle',
                filter: {
                    type: 'input'
                }
            },
            {
                title: '备注',
                field: 'remark',
                align: "center",
                filter: {
                    type: 'input'
                }
            },
            {
                title: '操作',
                width:300,
                align: "center",
                valign: 'middle',
                formatter: function (value, row) {
                    var html = '<a onclick="deletePurchase(this)" href="javascript:void(0);"  data-purchase="' + row.purchase_id + '"> 删除</a>';
                    return html;
                }
            }
        ];
        initTable(url, columns, 'server', InitSubTable);
    }


    InitSubTable = function (index, row, $detail) {
        var tableId = "cur_table_"+index;
        $detail.html('<table id="'+ tableId+ '"></table>').find('table');
        var purchaseId = row.purchase_id;
        var url = '{:url("storage/Purchase/getPurchaseDetail")}?purchaseId=' + purchaseId;
        var column = [
            {
                title: '序号',
                width: 50,
                align: "center",
                valign: 'middle',
                formatter: function (value, row, index) {
                    return index + 1;
                }
            },
            {
                title: 'uuid',
                field: 'uuid',
                visible: false
            },
            {
                title: '物料号',
                field: 'sub_materiel_id',
                align: "center",
                filter: {
                    type: 'input'
                }
            },
            {
                title: '条码',
                field: 'reel_id',
                align: "center",
                filter: {
                    type: 'input'
                }
            },
            {
                title: '数量',
                field: 'count',
                align: "center",
                filter: {
                    type: 'input'
                }
            },
            {
                title: '供应商',
                field: 'company_name',
                width:300,
                align: "center",
                valign: 'middle',
                filter: {
                    type: 'input'
                }
            },

        ];
        initSubTable(tableId,url, column, 'server');
    };

    deletePurchase = function (that) {
        var purchaseId = $(that).data('purchase');
        var url = "{:url('Purchase/deletePurchase')}";
        var param = {purchaseId: purchaseId};
        reviseTable('是否删除入库单' + purchaseId, url, param);
    }
</script>

</html>

